package com.oromwin.repos.spike;

//import java.io.File;
import org.apache.commons.logging.Log;
import com.oromwin.repos.client.SimpleReposClient;
import com.oromwin.repos.common.Logger;

public class HelloWorld {
    private static Log log = Logger.getLog(SimpleReposClient.class);
    private static final String Volume = "Volume";
    private static final String Media = "Media";
    private static final String File = "File";
    private static final String create = "create";
    private static final String delete = "delete";
    private static final String save = "save";
    
    public static void printUsage(String params) {
        StringBuffer sb = new StringBuffer();
        sb.append("java ").append(SimpleReposClient.class.getName()).append(" [ ");
        sb.append(Volume).append(" | ").append(Media).append(" | ").append(File).append(" ] [ ");
        sb.append(create).append(" | ").append(delete).append(" | ").append(save).append(" ] [ ");
        sb.append(params).append(" ]");
        System.out.println(sb.toString());
    }
    public static void main(String[] args) {
        if (args.length < 3) {
            printUsage("parameters");
            System.exit(0);
        }
        String target = args[0];
        String command = args[1];
//        if (log.isDebugEnabled()) printUsage("parameters");
        try {
            if (target.equalsIgnoreCase(Volume)) {
                if (args.length == 3) {
//                    String arg1 = args[2];
                    if (command.equalsIgnoreCase(create)) {
                        System.out.println("client.createVolume(arg1);");
                    } else if (command.equalsIgnoreCase(delete)) {
                        System.out.println("client.deleteVolume(arg1);");
                    } else {
                        SimpleReposClient.printUsage("VolumeName");
                    }
                } else {
                    printUsage("parameters");
                }
            } else if (target.equalsIgnoreCase(Media)) {
                if (command.equalsIgnoreCase(create)) {
                    if (args.length == 5) {
//                        String arg1 = args[2];
//                        File arg2 = new File(args[3]);
//                        long arg3 = Long.parseLong(args[4]);
                        System.out.println("client.createMedia(arg1, arg2, arg3);");
                    } else {
                        SimpleReposClient.printUsage("VolumeName MediaPath MediaMaxBytes");
                    }
                } else if (command.equalsIgnoreCase(delete)) {
                    if (args.length == 4) {
//                        String arg1 = args[2];
//                        File arg2 = new File(args[3]);
                        System.out.println("client.deleteMedia(arg1, arg2);");
                    } else {
                        SimpleReposClient.printUsage("VolumeName MediaPath");
                    }
                } else {
                    printUsage("parameters");
                }
            } else if (target.equalsIgnoreCase(File)) {
                if (command.equalsIgnoreCase(create)) {
                    if (args.length == 4) {
//                        String arg1 = args[2];
//                        File arg2 = new File(args[3]);
                        System.out.println("String fileId = client.createFile(arg1, arg2);");
                        System.out.println("System.out.println(Retrieved fileId is + fileId );");
                    } else {
                        SimpleReposClient.printUsage("VolumeName FilePath");
                    }
                } else if (command.equalsIgnoreCase(delete)) {
                    if (args.length == 4) {
//                        String arg1 = args[2];
//                        String arg2 = args[3];
                        System.out.println("client.deleteFile(arg1, arg2);");
                    } else {
                        SimpleReposClient.printUsage("VolumeName FileId");
                    }
                } else if (command.equalsIgnoreCase(save)) {
                    if (args.length == 5) {
//                        String arg1 = args[2];
//                        String arg2 = args[3];
//                        File arg3 = new File(args[4]);
                        System.out.println("client.saveFile(arg1, arg2, arg3);");
                    } else {
                        SimpleReposClient.printUsage("VolumeName FileId LocalFilePath");
                    }
                } else {
                    printUsage("parameters");
                }
            } else {
                printUsage("parameters");
            }
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
        log.info("OK");
        System.exit(0);
    }
}
